package com.qububu.emporium.goods.dto;

import java.util.Arrays;

/**
 * 商品状态
 * */
public enum GoodsStatus {
	DELETED(-1),
	HOT(0),
	NEW(1);
	
	private int intValue;
	
	private GoodsStatus(int intValue) {
		this.intValue = intValue;
	}

	public static GoodsStatus getType(String strValue) {
		try {
			GoodsStatus type = valueOf(strValue);
			return type;
		}
		catch(Exception ex) {
			throw new IllegalArgumentException("Value '" + strValue + "' is not allowed in GoodsStatus. Only "
					+ Arrays.toString(GoodsStatus.values()) + " are allowed."
					);
		}
	}
	
	public static GoodsStatus getType(int intValue) {
		for (GoodsStatus elem : GoodsStatus.values()) {
			if (elem.toIntValue() == intValue) {
				return elem;
			}
		}

		throw new IllegalArgumentException("Value '" + intValue
				+ "' is not allowed in GoodsStatus.");
	}
	
	public int toIntValue() {
		return intValue;
	}
}
